package org.edu.dao.impl;

import java.util.List;

import org.edu.dao.SemesterDao;
import org.edu.model.Semester;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Repository;

import org.edu.util.HibernateUtil;

@Scope
@Repository
public class SemesterDaoImpl implements SemesterDao {

	@Autowired
	private SessionFactory sessionFactory;

	public SemesterDaoImpl() {
		// TODO Auto-generated constructor stub
	}

	@Override
	public void save(Semester semester) throws Exception {
		sessionFactory.getCurrentSession().save(semester);
	}

	@Override
	public void update(Semester semester) throws Exception {
		sessionFactory.getCurrentSession().update(semester);
	}

	@Override
	public void remove(Semester semester) throws Exception {
		sessionFactory.getCurrentSession().delete(semester);
	}

	@Override
	public List<Semester> semesters() {
		return sessionFactory.getCurrentSession().createQuery("from Semester").list();
	}

	@Override
	public Semester findById(Long semester_id) throws Exception {
		return (Semester) this.sessionFactory.getCurrentSession().load(Semester.class, semester_id);
	}
}
